#include <iostream>
using namespace std;

typedef struct staff
{
    int worknum;
    char name[5];
    int base;
    int duty;
    int household;
    int tax;
    int real;
}STAFF;

void Input(STAFF *worker,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        cout<<"please input the ID of the No."<<i+1<<" staff: ";
        cin>>worker[i].worknum;
        cout<<"please input the name of the No."<<i+1<<" staff: ";
        cin>>worker[i].name;
        cout<<"please input the basic wage of the No."<<i+1<<" staff: ";
        cin>>worker[i].base;
        cout<<"please input the duty wage of the No."<<i+1<<" staff: ";
        cin>>worker[i].duty;
        cout<<"please input the household cost of the No."<<i+1<<" staff: ";
        cin>>worker[i].household;
        cout<<"please input the tax of the No."<<i+1<<" staff: ";
        cin>>worker[i].tax;
        cout<<endl;
    }
}

void CalReal(STAFF *worker,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        worker[i].real=worker[i].base+worker[i].duty-worker[i].household-worker[i].tax;
    }
}

void SortDes(STAFF *worker,int n)
{
    int i,j;
    STAFF temp;
    for(i=0;i<n;i++)
    {
        for(j=i;j<n;j++)
        {
            if(worker[i].real<worker[j].real)
            {
                temp=worker[i];
                worker[i]=worker[j];
                worker[j]=temp;
            }
        }
    }
}

void Output(STAFF *worker,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        cout<<worker[i].worknum<<" ";
        cout<<worker[i].name<<" ";
        cout<<worker[i].base<<" ";
        cout<<worker[i].duty<<" ";
        cout<<worker[i].household<<" ";
        cout<<worker[i].tax<<" ";
        cout<<worker[i].real<<endl;
    }
}

int main()
{
    int n;
    cout<<"How many staffs: n=";
    cin>>n;
    STAFF worker[n];
    Input(worker,n);
    CalReal(worker,n);
    SortDes(worker,n);
    Output(worker,n);

    return 0;
}
